# Replication File for
# "Coalition Inclusion Probabilities: A Party-Strategic
# Measure for Predicting Policy and Politics
# Authors: Mark A. Kayser, Matthias Orlowski
# and Jochen Rehmert
# Code to replicate Table E2


# set your directory to the folder with
# "data_estimation.RDS" data file 
setwd('...')


# load estimation data
dat.pf <- readRDS("data_estimation.RDS")
 
library(stargazer);library(mclogit)

# create numeric indicators of formation opportunities
dat.pf$case_id_num <- as.numeric(as.factor(dat.pf$case_id))

# final model on "western" sample; using coefficients from prior model as starting values
fin.oecd.pf <- mclogit(cbind(realg,case_id_num ) ~  dompar + np1 + domp1 + adomp1 +  naminor + namginv + naminwin + nanumpar + namedian + 
                         gdiv1 + sq + cab_hist + anti +  nasecond + nathird , data=dat.pf[dat.pf$cee ==0 ,], 
                       model = TRUE, x = T, y = TRUE ,
                       start= c(1.156, -0.938, 2.879, .576,
                                -1.798, -0.426, 0.869,
                                -0.636, 0.653, -0.641, 2.692,
                                0.077, -1.828, 0.728, 0.998)  )

# CEE samples; Poland's Suchoka I cabinet excluded to avoid convergence issues
fin.cee.pf <- mclogit(cbind(realg,case_id_num ) ~ dompar +  naminor +  naminwin + nanumpar + namedian + 
                        gdiv1 + sq + cab_hist + anti +  nasecond + nathird , data=dat.pf[dat.pf$cee ==1 & dat.pf$case_id != "Poland_Suchocka I" ,], model = TRUE, x = T, y = TRUE, 
                      start=c(1.444,0.402,1.714,
                              -0.195,0.695,-0.428,
                              2.419, 1.524, -0.092,
                              0.096, 0.303) )
 
# ----- Table E2 ----- #
stargazer(fin.oecd.pf, fin.cee.pf,
          add.lines = list(c("Observations",nrow(fin.oecd.pf$model),
                             nrow(fin.cee.pf$model)),
                           c("Countries", 20, 11),
                           c("Form. Opp.", length(unique(fin.oecd.pf$model$`cbind(realg, case_id_num)`[,2])),
                             length(unique(fin.cee.pf$model$`cbind(realg, case_id_num)`[,2]))),
                           c("Log-Likelihood", round(fin.oecd.pf$ll,3), round(fin.cee.pf$ll,3)) ),
          out = "tableE2.tex")
  
# the "observations" reported from the mclogit objects diverge from 
# the actual number for some reason; we calculate the actual number
# by counting the number of unique formation opportunities from
# the data frame used in the estimation
